
// DOM

function $(name)
{
  return document.getElementById(name);
}

function rgb(r,g,b,a)
{
  return new Colour(r,g,b,a);
}

function Colour(r,g,b,a)
{
  this.r = r;
  this.g = g;
  this.b = b;
  
  if(a != null)
    this.a = a;
  else
    this.a = null;
}

Colour.prototype.toString = function ()
{
  if(this.a == null)
    return 'rgb(' + this.r + ',' + this.g + ',' + this.b + ')';
  else
    return 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + (this.a / 255) + ')';
}

Colour.prototype.compare = function (colour,noAlpha)
{
  if(noAlpha == true)
    return this.r == colour.r && this.g == colour.g && this.b == colour.b;
  else
    return this.r == colour.r && this.g == colour.g && this.b == colour.b && this.a == colour.a;
}

Colour.prototype.clone = function ()
{
  return new Colour(this.r,this.g,this.b,this.a);
}

// FUNCTION

function isArray(object)
{
  return typeof(object) == 'object' && object instanceof Array;
}

function isArrayN(object,size)
{
  return isArray(object) && object.length == size;
}

function bind(scope, fn) 
{
    return function () 
    {
        fn.apply(scope, arguments);
    };
}

// OPERATOR

Function.prototype.inherit = function (superClass)
{
  for(var i in superClass.prototype)
    this.prototype[i] = superClass.prototype[i];
    
  this.prototype.constructor = this;
}
